/*
 * 版权所有 (c) 2022-2099 TBIT。保留所有权利。
 */

package com.tbit.uqbike.webmanager.controller;


import com.tbit.uqbike.object.value.LoginInfo;
import com.tbit.uqbike.object.view.JsonResult;
import com.tbit.uqbike.service.business.TempPowerService;
import com.tbit.uqbike.webmanager.req.TempPowerCheckReqVO;
import com.tbit.uqbike.webmanager.req.TempPowerOnReqVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * 临时通电
 *
 * @author yao
 * @since 2024/7/4 16:30
 */
@RestController
@RequestMapping("/tempPower")
@Validated
public class TempPowerController {

    @Resource
    private TempPowerService tempPowerService;

    @Resource
    private HttpServletRequest request;

    /**
     * 检查是否允许临时通电
     */
    @GetMapping("/check")
    public JsonResult checkTempPower(@Valid TempPowerCheckReqVO reqVO) {
        return JsonResult.ok(tempPowerService.checkTempPower(reqVO));
    }

    /**
     * 临时通电
     */
    @PostMapping("/powerOn")
    public JsonResult powerOn(@Valid @RequestBody TempPowerOnReqVO reqVO) {

        LoginInfo login = BaseController.getLogin(request);
        reqVO.setOpId(login.getAccountUserId());

        tempPowerService.powerOn(reqVO);
        return JsonResult.ok();
    }

}
